package sketch;

import java.awt.*;
import javax.swing.*;

/**
 * 
 * @author Indrojeet Mondal
 * @version 0.1
 *
 */
class CButtonPanel extends JPanel
{
	// the color to show on the button; default is black
	private Color color = new Color(0, 0, 0);
	
	public CButtonPanel(Color color)
	{
		this.color = color;
		
	}
	public Color getColor()
	{
		return color;
	}
	public void setColor(Color c)
	{
		if (c == null)
			return;
		color = c;
		repaint();
	}
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		Rectangle r = this.getVisibleRect();
		g.setColor(color);
		g.fill3DRect(r.x, r.y, r.width, r.height, true);
	}
}
class ColorButton extends JButton
{
	private CButtonPanel panel;
	
	public ColorButton(Color color)
	{
		if (color == null)
			panel = new CButtonPanel(Color.BLACK);
		else
			panel = new CButtonPanel(color);
		add(panel);
		
	}
	public Color getChosenColor()
	{
		Color c = JColorChooser.showDialog(ColorButton.this, "Choose color", panel.getColor());
		panel.setColor(c);
		return c;
	}
}
